<?php
/**********************************************************************************
WIKINDX: Bibliographic Management system.
Copyright (C)

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program;
if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

The WIKINDX Team 2007
sirfragalot@users.sourceforge.net
**********************************************************************************/
/*****
* RESOURCEVIEW class
*
* View a single resource.
*
* $Header: /cvsroot/wikindx/wikindx3/core/resource/RESOURCEVIEW.php,v 1.59 2007/12/18 14:49:31 sirfragalot Exp $
*****/
class RESOURCEVIEW
{
// Constructor
	function RESOURCEVIEW($db, $vars)
	{
		$this->db = $db;
		$this->vars = $vars;
		include_once("core/session/SESSION.php");
		$this->session = new SESSION();
		include_once("core/messages/MESSAGES.php");
		$this->messages = new MESSAGES();
		include_once("core/messages/ERRORS.php");
		$this->errors = new ERRORS();
		include_once("core/html/MISC.php");
		include_once("core/html/FORM.php");
		include_once("core/html/HTML.php");
		$this->html = new HTML();
		include_once("core/html/TABLE.php");
		include_once("core/resource/RESOURCEABSTRACT.php");
		include_once("core/resource/RESOURCENOTE.php");
		include_once("core/resource/RESOURCECUSTOM.php");
		include_once("core/resource/RESOURCEQUOTE.php");
		include_once("core/resource/RESOURCEPARAPHRASE.php");
		include_once("core/resource/RESOURCEMUSING.php");
		include_once("core/cite/CITE.php");
		include_once("core/group/GROUP.php");
		include_once("core/keyword/KEYWORD.php");
		include_once("core/icons/LOADICONS.php");
		$this->icons = new LOADICONS();
		include_once("core/attachments/ATTACHMENTS.php");
	}
// Select a random resource ID for viewing
	function random()
	{
		$sql = $this->db->selectNoExecute(array('WKX_resource'), array('id'), " ORDER BY RAND()");
		$recordset = $this->db->limit($sql, 1, 0);
		if(!$this->db->numRows($recordset))
			$this->badInput($this->messages->text("misc", "noResources"));
		$this->vars['id'] = $this->db->fetchOne($recordset);
		$this->vars['access'] = TRUE; // Increment num. views.
		return $this->view();
	}
	function view($message = FALSE, $lastSolo = FALSE)
	{
		$this->session->delVar('attachMaxSize'); // Set in attachments/ATTACHMENTS::fileAttachForm().  Always clear it here.
		$this->updateAccesses();
		if($lastSolo)
			$this->vars['id'] = $this->session->getVar('sql_lastSolo');
		if(!array_key_exists('id', $this->vars) || !$this->vars['id'])
			$this->badInput($this->errors->text("inputError", "missing"));
		$this->session->setVar("sql_lastSolo", $this->vars['id']);
		$this->session->setVar("sql_lastView", 'solo');
		$row = $this->grabResource();
		$pString = $message ? $message : FALSE;
		$attachments = new ATTACHMENTS($this->db, $this->vars);
		$this->attachments = $attachments->attachedFiles($row['resourceId']);
		$this->hasAttachments = $attachments->hasAttachments;
		$pString .= $this->showResource($row);
		$pString .= TABLE::tdEnd();
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($this->attachments);
		unset($attachments);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$abstract = new RESOURCEABSTRACT($this->db, $this->vars);
		$pString .= TABLE::td($abstract->view($row));
		unset($abstract);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($this->showUrl($row));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($this->showDoi($row));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$note = new RESOURCENOTE($this->db, $this->vars);
		$pString .= TABLE::td($note->view($row));
		unset($note);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$custom = new RESOURCECUSTOM($this->db, $this->vars);
		$pString .= TABLE::td($custom->view($row));
		unset($custom);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$quote = new RESOURCEQUOTE($this->db, $this->vars);
		$pString .= TABLE::td($quote->view($this->vars['id']));
		unset($quote);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$paraphrase = new RESOURCEPARAPHRASE($this->db, $this->vars);
		$pString .= TABLE::td($paraphrase->view($this->vars['id']));
		unset($paraphrase);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$pString .= TABLE::tdStart();
		$musing = new RESOURCEMUSING($this->db, $this->vars);
		$pString .= $musing->view($this->vars['id']);
		unset($musing);
// Turn on the 'add bookmark' menu item
		$this->session->setVar("bookmark_displayAdd", TRUE);
		include_once("core/template/TEMPLATE.php");
		$template = new TEMPLATE('content');
		$template->setVar('heading', $this->messages->text("heading", "resources"));
		$template->setVar('body', $pString);
		return $template->process();
	}
// Increment the accesses counter for this resource
	function updateAccesses()
	{
// Only increment when viewing from a list/select/search operation or after displaying metadata i.e. not from front page, lastSolo  etc.)
		if(!array_key_exists("access", $this->vars) || !array_key_exists("id", $this->vars))
			return;
		$this->db->updateSingle('WKX_resource_misc', 
			$this->db->formatField('accesses') .  "=" . 
			$this->db->formatField('accesses') . "+" . $this->db->tidyInput(1), 
			" WHERE " . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->vars['id']));
	}
// Grab resource from database
	function grabResource()
	{
		include_once("core/sql/STATEMENTS.php");
		$stmt = new STATEMENTS($this->db);
// fields from WKX_resource_note, WKX_resource_category, WKX_resource_keyword and WKX_abstract:
		$array = array("text", "categories", "keywords", "abstract", "addUserIdAbstract", "editUserIdAbstract",
			"addUserIdNote", "editUserIdNote",);
		$sql = $this->db->selectNoExecute(array("WKX_resource"), array_merge($stmt->listFields(), $array),
			$stmt->selectJoin());
		$sql .= " WHERE WKX_resource.id=" . $this->db->tidyInput($this->vars['id']);
		$recordset = $this->db->query($sql);
		if(!$this->db->numRows($recordset))
			$this->badInput($this->messages->text("resources", "noResult"));
		return $this->db->fetchRow($recordset);
	}
// display bibliographic entry
	function showResource($row)
	{
		include_once("core/styles/BIBSTYLE.php");
		$bibStyle = new BIBSTYLE($this->db, "html");
		include_once("core/file/export/COINS.php");
		$coins = new COINS($this->db);
		include("config.php");
		$this->icons->getIconInfo('bibtex');
		$this->bibtexLink = $this->icons->bibtexExists ? "imgLink" : "link";
		$this->icons->getIconInfo('edit');
		$editLink = $this->icons->editExists ? "imgLink" : "link";
		$this->icons->getIconInfo('delete');
		$deleteLink = $this->icons->editExists ? "imgLink" : "link";
		$edit = $delete = $allowEdit = FALSE;
// bibtex export link
		$bibtex = "&nbsp;" . $this->bibtexLink($row['resourceId']) . "&nbsp;";
		if($this->session->getVar('setup_write') && !$WIKINDX_ORIGINATOR_EDITONLY)
		{
			$edit = MISC::a($editLink, "&nbsp;" . $this->icons->edit .
				"&nbsp;", "index.php?action=resourceEdit" . htmlentities("&id=" . $row['resourceId']));
			$allowEdit = TRUE;
		}
		else if($this->session->getVar('setup_write') && ($row['addUserIdResource'] == $this->session->getVar('setup_userId')))
		{
			$edit = MISC::a($editLink, "&nbsp;" . $this->icons->edit .
				"&nbsp;", "index.php?action=resourceEdit" . htmlentities("&id=" . $row['resourceId']));
			$allowEdit = TRUE;
		}
		if(array_key_exists("search", $this->vars) && $this->vars["search"] = 'highlight')
		{
			$searchTerms = explode(",", $this->session->getVar('search_highlight'));
			foreach($searchTerms as $term)
				$patterns[] = "/($term)/i";
			$pString = $this->previousNextLinks($row['resourceId'], TRUE);
			$bibStyle->bibformat->patterns = $patterns;
		}
		else
			$pString = $this->previousNextLinks($row['resourceId'], FALSE);
		$nextDelete = $this->nextDelete ? htmlentities("&nextDelete=" . $this->nextDelete) : FALSE;
		if($this->session->getVar('setup_superadmin'))
		{
			if(!$edit)
				$edit = MISC::a($editLink, "&nbsp;" . $this->icons->edit .
					"&nbsp;", "index.php?action=resourceEdit" . htmlentities("&id=" . $row['resourceId']));
			$delete = MISC::a($deleteLink, "&nbsp;" . $this->icons->delete .
			"&nbsp;", "index.php?action=deleteResourceConfirm" . 
			htmlentities("&resource_id=" . $row['resourceId']) . $nextDelete);
			$allowEdit = TRUE;
		}
		if($this->session->getVar("setup_useBibtexKey"))
		{
			$recordSet = $this->db->select(array('WKX_import_raw'), array('text', 'importType'), 
				"WHERE " . $this->db->formatField('id') . "=" . $this->db->tidyInput($row['resourceId']) . 
				" AND " . $this->db->formatField('importType') . "=" . $this->db->tidyInput('bibtex'));
			if($this->db->numRows($recordSet))
			{
				$rawRow = $this->db->fetchRow($recordSet);
				$rawEntries = unserialize(base64_decode($rawRow['text']));
				$rawEntries = explode("\n", $rawEntries);
				array_pop($rawEntries); // always an empty array at end so get rid of it.
				foreach($rawEntries as $entries)
				{
					$entry = explode("=", $entries, 2);
					if(!trim($entry[1]))
						continue;
					if(trim($entry[0]) == 'citation')
					{
						$bibtexKey = trim($entry[1]);
						break;
					}
				}
			}
		}
		if(!isset($bibtexKey))
		{
			if($this->session->getVar("setup_useWikindxKey"))
			{
				include_once("core/file/export/BIBTEX.php");
				$bibtex = new BIBTEX($this->db, FALSE);
				$bibtex->rawCitation = FALSE;
				$bibtex->loadArrays();
				$bibtexKey = $bibtex->citeFormat($row);
				unset($bibtex);
			}
			else
				$bibtexKey = $row['bibtexKey'];
		}
		$bibtexKey = $this->messages->text("misc", "bibtexKey") . "&nbsp;&nbsp;" . $bibtexKey;
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td(MISC::span($this->messages->text("resourceType", $row['type']) . ":"), "hint");
		$pString .= TABLE::td(MISC::span($this->showIsbn($row)), "hint", "center");
		$pString .= TABLE::td(MISC::span($bibtexKey), "hint");
// Email link to friend
		if($link = $this->friendLink($row['resourceId']))
			$pString .= TABLE::td($link, FALSE, 'right');
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
// Encapsulating table from template
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		include_once("core/user/USER.php");
		$user = new USER($this->db);
		$userAddEdit = $user->displayUserAddEdit($row['addUserIdResource'], $row['editUserIdResource'], FALSE, 
			"&nbsp;" . str_replace(" ", "&nbsp;", $row['timestamp']), 
			"&nbsp;" . str_replace(" ", "&nbsp;", $row['timestampAdd']));
// write Coins <span> data
		$coinsString = $coins->coinsDisplay($row);
		$pString .= TABLE::td($coinsString . $bibStyle->process($row) . $userAddEdit, "alternate1");
		$pString .= TABLE::td($bibtex . $edit . $delete, "alternate1", "right", "top");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
// Encapsulating table from template
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
// This table encloses categories through basket in the 1st. column and the statistics in the 2nd column
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$td = FALSE;
// Display resource's categories
		$editLink = $this->getCategoryKeyword($row, $allowEdit, $editLink, $this->icons->edit);
		if($row['categories'])
			$td .= $this->showCategories($row, $editLink);
// If this resource has keywords, show them
		if($row['keywords'])
			$td .= $this->showKeywords($row, $editLink);
		$td .= $this->showCreators($row);
		if($row['publisher'])
			$td .= $this->showPublisher($row);
		if($row['collection'])
			$td .= $this->showCollection($row);
// Show user bibliographies this resource is in
		if($bibs = $this->showBibliographies($row))
			$td .= $bibs;
// See if this resource has citations or is cited itself
		$cite = new CITE($this->db, $this->vars);
		$td .= $cite->showCitations($row['resourceId']);
		$td .= $this->basket($row['resourceId']);
		if($td)
			$pString .= TABLE::td($td);
		if($this->session->getVar("setup_multiUser"))
			$pString .= TABLE::td($this->statistics($row), FALSE, "right", "top");
// end enclosure of categories, etc. and statistics.
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr() . "&nbsp;" . MISC::br();
		return $pString;
	}
// Email this link to a friend
// Only available in multi_user setup where direct (i.e. non-login) READONLY is available
	function friendLink($id)
	{
		include("config.php");
		if($this->session->getVar("setup_multiUser") && $WIKINDX_READONLYACCESS && $WIKINDX_MAIL_SERVER)
		{
			$linkStyle = "link linkCiteHidden";
			$link = $this->messages->text("misc", "emailToFriend");
// link is actually a JavaScript call
			return MISC::span("&nbsp;&nbsp;" . MISC::a($linkStyle, $link, 
				"javascript:openEmailFriendWindow('index.php?action=emailFriendDisplay" . "&amp;id=$id')"), "small");
		}
		return FALSE;
	}
// View the resource in a pop up as bibtex
	function bibtexLink($id)
	{
// display bibtex link
// link is actually a JavaScript call
			return MISC::a($this->bibtexLink, $this->icons->bibtex, 
				"javascript:openBibtexWindow('index.php?action=bibtexDisplay" . "&amp;id=$id')");
	}
// Popularity accesses, maturity inex etc.   Only the admin can change the maturityIndex
	function statistics($row)
	{
		$pString = '';
		if($row['peerReviewed'] == 'Y')
			$pString .= MISC::span($this->messages->text("resources", "peerReviewed"), "small") . MISC::br();
		include_once("core/statistics/STATISTICS.php");
		$stats = new STATISTICS($this->db, FALSE);
		$pString .= MISC::span($this->messages->text("viewResource", "numAccesses", 
			"&nbsp;&nbsp;" . $row['accesses']), "small") . MISC::br();
		$stats->getMaxAccesses();
		$pString .= MISC::span($this->messages->text("viewResource", "popularity", 
			"&nbsp;&nbsp;" . $stats->getPopularityIndex($row['accesses'])), "small") . MISC::br();
		if($this->hasAttachments)
			$pString .= MISC::span($this->messages->text("viewResource", "numDownloads", 
				"&nbsp;&nbsp;" . $row['attachDownloads']), "small") . MISC::br();
		if($this->session->getVar('setup_superadmin'))
		{
			$pString .= FORM::formHeader('setMaturityIndex');
			$pString .= FORM::hidden("resourceId", $row['resourceId']);
			$pString .= MISC::span($this->messages->text("viewResource", "maturityIndex"), "small") . 
				"&nbsp;&nbsp;" . FORM::textInput(FALSE, "maturityIndex", $row['maturityIndex'], 5, 4);
			$pString .= "&nbsp;" . FORM::formSubmit('Submit');
			$pString .= MISC::br() . $this->messages->text("hint", "maturityIndex");
			$pString .= FORM::formEnd();
		}
		else if($row['maturityIndex'])
			$pString .= MISC::span($this->messages->text("viewResource", "maturityIndex", 
				"&nbsp;&nbsp;" . $row['maturityIndex'] . "/10"), "small");
		return $pString;
	}
// Add controls for adding to and removing from resource basket
	function basket($resourceId)
	{
		if($this->session->issetVar('basket_list'))
		{
			$basket = unserialize($this->session->getVar('basket_list'));
			if(array_search($resourceId, $basket) !== FALSE)
			{
				$string = MISC::br() . FORM::formHeader('basketRemove');
				$string .= FORM::hidden("resourceId", $resourceId);
				$string .= FORM::formSubmit('basketRemove');
				$string .= FORM::formEnd();
				return $string;
			}
		}
		$string = MISC::br() . FORM::formHeader('basketAdd');
		$string .= FORM::hidden("resourceId", $resourceId);
		$string .= FORM::formSubmit('basketAdd');
		$string .= FORM::formEnd();
		return $string;
	}
// Show previous and next resource hyperlinks.
	function previousNextLinks($thisId, $highlight)
	{
		if($this->vars['action'] == 'randomResource')
			return $this->nextRandomLink($thisId);
		$this->nextDelete = FALSE;
		if(($raw = $this->session->getVar("list_allIds")) === FALSE)
		{
			$this->nextDelete = 'NULL';
			return FALSE;
		}
// Search highlighting in force?
		$highlight = $highlight ? htmlentities("&search=highlight") : FALSE;
// type of CSS class required.
		$this->icons->getIconInfo("next");
		$this->icons->getIconInfo("previous");
		$nextClass = $this->icons->nextExists ? "imgLink" : "link";
		$previousClass = $this->icons->previousExists ? "imgLink" : "link";
		$allIds = unserialize(base64_decode($raw));
		$thisKey = array_search($thisId, $allIds);
		if($thisKey)
			$tdLeft = MISC::a($previousClass, $this->icons->previous, "index.php?action=resourceView" .
				htmlentities("&id=" . $allIds[$thisKey - 1]) . $highlight);
		else
			$tdLeft = "&nbsp;";
		if($thisKey < (sizeof($allIds) - 1))
			$tdRight = MISC::a($nextClass, $this->icons->next, "index.php?action=resourceView" .
				htmlentities("&id=" . $allIds[$thisKey + 1]) . $highlight);
		else
			$tdRight = "&nbsp;";
		$pString = TABLE::tableStart(FALSE, 0, 10, 0, "center", 0);
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($tdLeft, FALSE, "right");
		$pString .= TABLE::td($tdRight, FALSE, "left");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		if($this->session->getVar('setup_superadmin'))
		{
			if(array_key_exists($thisKey + 1, $allIds))
				$this->nextDelete = $allIds[$thisKey + 1];
			else if(array_key_exists($thisKey - 1, $allIds))
				$this->nextDelete = $allIds[$thisKey - 1];
			else
				$this->nextDelete = 'NULL';
		}
		return $pString;
	}
// Show randmon resource hyperlink
	function nextRandomLink($thisId)
	{
		$this->nextDelete = FALSE;
		if(($raw = $this->session->getVar("list_allIds")) === FALSE)
		{
			$this->nextDelete = 'NULL';
			return FALSE;
		}
// type of CSS class required.
		$this->icons->getIconInfo("next");
		$nextClass = $this->icons->nextExists ? "imgLink" : "link";
		$allIds = unserialize(base64_decode($raw));
		$thisKey = array_search($thisId, $allIds);
		$td = MISC::a($nextClass, $this->icons->next, "index.php?action=randomResource");
		$pString = TABLE::tableStart(FALSE, 0, 10, 0, "center", 0);
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($td);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		if($this->session->getVar('setup_superadmin'))
		{
			if(array_key_exists($thisKey + 1, $allIds))
				$this->nextDelete = $allIds[$thisKey + 1];
			else if(array_key_exists($thisKey - 1, $allIds))
				$this->nextDelete = $allIds[$thisKey - 1];
			else
				$this->nextDelete = 'NULL';
		}
		return $pString;
	}
// Get categoris and keywords and create edit link
	function getCategoryKeyword($row, $allowEdit, $editLink, $editIcon)
	{
		$groupIds = $keywordIds = FALSE;
		foreach(split(",", $row['categories']) as $key => $value)
			$cats[] = "'$value'";
		$condition = $this->db->formatField('id') . "=" . join(" OR " .
			$this->db->formatField('id') . "=", $cats);
		$recordset = $this->db->select(array('WKX_category'), array("id", "category"), 
			" WHERE " . $condition . " ORDER BY " . $this->db->formatField('category'));
		while($line = $this->db->loopRecordSet($recordset))
		{
			$this->groupArray[$line['id']] = stripslashes($line['category']);
			$ids[] = $line['id'];
		}
		if(isset($ids))
		{
			$groupIds = htmlentities("&groupIds=" . join(',', $ids));
			unset($ids);
		}
		foreach(split(",", $row['keywords']) as $key => $value)
			$keywords[] = "'$value'";
		$condition = $this->db->formatField('id') . "=" . join(" OR " .
			$this->db->formatField('id') . "=", $keywords);
		$recordset = $this->db->select(array('WKX_keyword'), array("id", "keyword"), 
			" WHERE " . $condition . " ORDER BY " . $this->db->formatField('keyword'));
		while($line = $this->db->loopRecordSet($recordset))
		{
			$this->keywordArray[$line['id']] = stripslashes($line['keyword']);
			$ids[] = $line['id'];
		}
		if(isset($ids))
		{
			$keywordIds = htmlentities("&keywordIds=" . join(',', $ids));
			unset($ids);
		}
		$edit = FALSE;
		if($allowEdit)
			$edit = "&nbsp;&nbsp;" . MISC::a($editLink, "&nbsp;" . $editIcon .
				"&nbsp;", "index.php?action=resourceKeywordCategoryEdit" . 
				htmlentities("&id=" . $row['resourceId']) . $groupIds . $keywordIds);
		return $edit;
	}
// Show resource categories
	function showCategories($row, $edit)
	{
		$obj = new GROUP($this->db);
		$pString = FALSE;
		$title = $this->messages->text("resources", "categories");
		if(isset($this->groupArray))
		{
			foreach($this->groupArray as $cId => $category)
				$newArray[] = $obj->getCategoryLink($row['resourceId'], $cId, $category);
			$pString = MISC::span($title . ": " . join(", ", $newArray), "small") . $edit . MISC::br();
		}
		return $pString;
	}
// Show resource keywords
	function showKeywords($row, $edit)
	{
		$keywordObj = new KEYWORD($this->db, $this->vars);
		$pString = FALSE;
		$title = $this->messages->text("resources", "keywords");
		if(isset($this->keywordArray))
		{
			foreach($this->keywordArray as $keywordId => $keyword)
				$newArray[] = $keywordObj->getKeywordLink($row['resourceId'],
					$keywordId, $keyword);
			$pString = MISC::span($title . ": " . join(", ", $newArray), "small") . $edit . MISC::br();
		}
		return $pString;
	}
// show resource creators
	function showCreators($row)
	{
		include_once("core/creator/CREATOR.php");
		$obj = new CREATOR($this->db);
		foreach(split(",", $row['creator1']) as $key => $value)
			$creators[] = "'$value'";
		foreach(split(",", $row['creator2']) as $key => $value)
			$creators[] = "'$value'";
		foreach(split(",", $row['creator3']) as $key => $value)
			$creators[] = "'$value'";
		foreach(split(",", $row['creator4']) as $key => $value)
			$creators[] = "'$value'";
		foreach(split(",", $row['creator5']) as $key => $value)
			$creators[] = "'$value'";
		$creators = array_unique($creators);
		if(!isset($creators))
			return FALSE;
		$condition = $this->db->formatField('id') . "=" . join(" OR " .
			$this->db->formatField('id') . "=", $creators);
		$recordset = $this->db->select(array('WKX_creator'), array("id", "surname", "prefix"), 
			" WHERE " . $condition . " ORDER BY " . $this->db->formatField('surname'));
		while($line = $this->db->loopRecordSet($recordset))
		{
			if($line['prefix'])
				$name = $line['prefix'] . ' ' . $line['surname'];
			else
				$name = $line['surname'];
			$cArray[$line['id']] = stripslashes($name);
		}
		$title = $this->messages->text("creators", "creators");
		$pString = '';
		if(isset($cArray))
		{
			foreach($cArray as $cId => $name)
				$newArray[] = $obj->getCreatorLink($row['resourceId'], $cId, $name);
//			$pString = TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//			$pString .= TABLE::trStart();
			$pString = MISC::span($title . ": " . join(", ", $newArray), "small") . MISC::br();
//			$pString .= TABLE::trEnd();
//			$pString .= TABLE::tableEnd();
		}
		return $pString;
	}
// Show resource publisher
	function showPublisher($row)
	{
		include_once("core/publisher/PUBLISHER.php");
		$obj = new PUBLISHER($this->db);
		$pString = FALSE;
		if($row['publisherLocation'])
			$loc = ' (' . stripslashes($row['publisherLocation']) . ')';
		else
			$loc = FALSE;
		$name = stripslashes($row['publisherName']) . $loc;
		$title = $this->messages->text("resources", "publisher");
		$publisher = $obj->getPublisherLink($row['resourceId'], $row['publisher'], $name);
		$pString = MISC::span($title . ": " . $publisher, "small") . MISC::br();
		return $pString;
	}
// Show resource collection
	function showCollection($row)
	{
		include_once("core/collection/COLLECTION.php");
		$obj = new COLLECTION($this->db);
		$pString = FALSE;
		$title = $this->messages->text("resources", "collection");
		$collection = $obj->getCollectionLink($row['resourceId'], $row['collection'], 
			$this->html->dbToHtmlTidy(stripslashes($row['collectionTitle'])));
		$pString = MISC::span($title . ": " . $collection, "small") . MISC::br();
		return $pString;
	}
// Show users bibliographies this resource belongs to
	function showBibliographies($row)
	{
		$pString = FALSE;
		$title = $this->messages->text("resources", "bibliographies");
		$recordset = $this->db->select(array('WKX_user_bibliography'), array('id', 'title', 'bibliography'), 
			" WHERE " . 
			" FIND_IN_SET(" . $this->db->tidyInput($row['resourceId']) . ", CONCAT(" . 
				$this->db->formatfield('bibliography') . ", ','))" . 
			' ORDER BY ' . $this->db->tidyInputClause('title'));
		if(!$this->db->numRows($recordset))
			return FALSE;
		while($line = $this->db->loopRecordSet($recordset))
		{
			$newArray[] = MISC::a("link", $this->html->dbToHtmlTidy(stripslashes($line['title'])), 
				"index.php?action=bibliographies" . htmlentities("&method=displayBib") . htmlentities("&bibId=" . $line['id']));
		}
		$pString = MISC::span($title . ": " . join(", ", $newArray), "small") . MISC::br();
		return $pString;
	}
// Show ISBN or other identifier
	function showIsbn($row)
	{
		if(!$row['isbn'])
			return FALSE;
		$pString = $this->messages->text("resources", "isbn");
		$pString .= ":&nbsp;&nbsp;" . $this->html->dbToHtmlTidy($row['isbn']);
		return $pString;
	}
// If resource is not web_article, database or web_site display any URL given
	function showUrl($row)
	{
		if(($row['type'] == 'web_article') || ($row['type'] == 'web_site') || 
			($row['type'] == 'database') || !$row['url'])
			return FALSE;
		include_once("core/html/FORMMISC.php");
		$fm = new FORMMISC();
		$pString = MISC::b($this->messages->text("viewResource", "url"));
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$displayedUrl = $fm->reduceLongText($this->html->dbToHtmlTidy($row['url']), 80);
		$pString .= TABLE::td(MISC::a("link", $displayedUrl,
			$this->html->dbToHtmlTidy($row['url']), "_new"), "alternate1");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		return $pString;
	}
// Display any DOI link
	function showDoi($row)
	{
		include_once("core/html/FORMMISC.php");
		$fm = new FORMMISC();
		$displayedDoi = $fm->reduceLongText($this->html->dbToHtmlTidy($row['doi']), 80);
		if(!$displayedDoi)
			return '';
		$pString = MISC::b($this->messages->text("viewResource", "doi"));
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td(MISC::a("link", $displayedDoi,
			'http://dx.doi.org/' . $this->html->dbToHtmlTidy($row['doi']), "_new"), "alternate1");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		return $pString;
	}
// Error handling
	function badInput($error)
	{
		include_once("core/html/CLOSE.php");
		include_once("core/template/TEMPLATE.php");
		$template = new TEMPLATE('content');
		$template->setVar('heading', $this->messages->text("heading", "resources"));
		$template->setVar('body', $error);
		new CLOSE($this->db, $template->process());
	}
}
?>
